package com.liao.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.liao.dao.ReadingDao;
import com.liao.util.Result;

@RestController
public class ReadingController {
	@Autowired
	ReadingDao readingdao;

	@RequestMapping("/getReading")
	@ResponseBody
	public Object getReading(@RequestParam Map<String, Object> map) {
		Integer page = Integer.parseInt(map.get("page").toString());
		Integer limit = Integer.parseInt(map.get("limit").toString());		
		map.put("page", (page - 1) * limit);
		map.put("limit", limit);
		List<Map<String, Object>> user = readingdao.getReading(map);

//	if (rname == null || rname == "") {
//			rname = null;
//		}
//		if (rsort == null || rsort == "") {
//			rsort = null;
//	}
		int count = readingdao.getCount();// 获取总条数
		Result res = new Result("0", "true", count, user);
		return res;
	}
	//添加
	@RequestMapping("/addReading")
	@ResponseBody
	public Object addReading(@RequestParam Map<String, Object> map) {

		System.out.println(map.get("rname"));
		int i = readingdao.AddReading(map);
		Result res = new Result("0", "true", i, true);
		return res;
	}
	//修改
	@RequestMapping("/updateReading")
	@ResponseBody
	public Object updateReading(@RequestParam Map<String, Object> map) {

		int i = readingdao.UpdateReading(map);
		Result res = new Result("0", "true", i, true);
		return res;
	}

	@RequestMapping("/deleteReading")
	@ResponseBody
	public Object deleteReading(@RequestParam("rid") Integer rid) {
		int i = readingdao.DelectReading(rid);
		Result res = new Result("0", "true", i, true);
		return res;
	}
	
	
}
